package service.impl;

import dao.ProductMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import pojo.*;
import service.ProductService;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {
    @Resource
    private ProductMapper dao;

    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public Product getProduct(Product product) {
        return dao.getProduct(product);
    }

    @Override
    public Page<Product> getAllByPage1(Page<Product> page) {
        Page<Product> ProPage = new Page<>();
        //设置当前页
        ProPage.setCurrentPage(page.getCurrentPage());
        //设置每页条数
        ProPage.setPageSize(page.getPageSize());
        //设置每页数据
        ProPage.setLists(dao.getAllByPage1(page));
        //设置总条数
        ProPage.setTotalRecord(dao.getCount1());
        return ProPage;
    }
    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public int getProAdd(Product product) {
        return dao.getProAdd(product);
    }
    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public int getProupd(Product product) {
        return dao.getProupd(product);
    }
    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public int getProDel(String productCode) {
        int i = dao.getProDel(productCode);
        return i;
    }

    @Override
    public List<Product> productAllByPage(Page<Product> page, Product product) {
        return dao.productAllByPage(page,product);
    }

    @Override
    public int productCount(Page<Product> page, Product product) {
        return dao.ProductCount(page,product);
    }

    @Override
    public List<Product> productAllByPage1(Page<Product> page) {
        return dao.productAllByPage1(page);
    }

    @Override
    public int productCount1(Page<Product> page) {
        return dao.ProductCount1(page);
    }

    @Override
    public int addCheck(Checkstock checkstock) {
        Product product = new Product();
        product.setProductCode(checkstock.getProductCode());
        Product p =  dao.getProduct(product);
        checkstock.setOriginNum(p.getNum());
        Stockrecord stockrecord=new Stockrecord();
        stockrecord.setProductCode(checkstock.getProductCode());
        stockrecord.setCreateUser(checkstock.getCreateUser());
        if (!"".equals(checkstock.getType())){
            if(checkstock.getType().equals("损耗")){
                checkstock.setRealNum(p.getNum()-checkstock.getChangeNum());
                stockrecord.setStockType(4);
                stockrecord.setStockNum(-checkstock.getChangeNum());
            }else {
                checkstock.setRealNum(p.getNum()+checkstock.getChangeNum());
                stockrecord.setStockType(3);
                stockrecord.setStockNum(checkstock.getChangeNum());
            }
        }
        p.setNum(checkstock.getRealNum());
        dao.addStockrecord(stockrecord);
        dao.updateNum(p);
        int i = dao.addCheckstock(checkstock);
        return i;
    }

    @Override
    public List<Stockrecord> outStockReportPage(Page<Stockrecord> page, Stockrecord stockrecord) {
        return dao.outStockReportPage(page, stockrecord);
    }

    @Override
    public int outStockReportCount(Page<Stockrecord> page, Stockrecord stockrecord) {
        return dao.outStockReportCount(page, stockrecord);
    }

    @Override
    public List<Stockrecord> outStockReportPage1(Stockrecord stockrecord) {
        return dao.outStockReportPage1(stockrecord);
    }

    @Override
    public int outStockReportCount1(Stockrecord stockrecord) {
        return dao.outStockReportCount1(stockrecord);
    }

    @Override
    public List<Stockrecord> inStockReportPage(Page<Stockrecord> page, Stockrecord stockrecord) {
        return dao.inStockReportPage(page,stockrecord);
    }

    @Override
    public int inStockReportCount(Page<Stockrecord> page, Stockrecord stockrecord) {
        return dao.inStockReportCount(page, stockrecord);
    }

    @Override
    public List<Stockrecord> inStockReportPage1(Stockrecord stockrecord) {
        return dao.inStockReportPage1(stockrecord);
    }

    @Override
    public int inStockReportCount1(Stockrecord stockrecord) {
        return dao.inStockReportCount1(stockrecord);
    }

    @Override
    public List<Stockrecord> stockChangePage(Page<Stockrecord> page, Stockrecord stockrecord) {
        return dao.stockChangePage(page,stockrecord);
    }

    @Override
    public int stockChangeCount(Page<Stockrecord> page, Stockrecord stockrecord) {
        return dao.stockChangeCount(page, stockrecord);
    }

    @Override
    public List<Stockrecord> stockChangePage1(Stockrecord stockrecord) {
        return dao.stockChangePage1(stockrecord);
    }

    @Override
    public int stockChangeCount1(Stockrecord stockrecord) {
        return dao.stockChangeCount1(stockrecord);
    }

    @Override
    public List<Payrecord> getPayRecord(Page<Payrecord> page, Payrecord payrecord) {
        return dao.getPayRecord(page,payrecord);
    }

    @Override
    public int getPayRecordCount(Page<Payrecord> page, Payrecord payrecord) {
        return dao.getPayRecordCount(page,payrecord);
    }

    @Override
    public List<Payrecord> getPayRecord1(Page<Payrecord> page, Payrecord payrecord) {
        return dao.getPayRecord1(page,payrecord);
    }

    @Override
    public int getPayRecordCount1(Page<Payrecord> page, Payrecord payrecord) {
        return dao.getPayRecordCount1(page, payrecord);
    }

    @Override
    public List<Payrecord> getPayRecordInMoney(Payrecord payrecord) {
        return dao.getPayRecordInMoney(payrecord);
    }

    @Override
    public int getPayRecordInMoneyCount(Payrecord payrecord) {
        return dao.getPayRecordInMoneyCount(payrecord);
    }

    @Override
    public List<Payrecord> getPayRecordOutMoney(Payrecord payrecord) {
        return dao.getPayRecordOutMoney(payrecord);
    }

    @Override
    public int getPayRecordOutMoneyCount(Payrecord payrecord) {
        return dao.getPayRecordOutMoneyCount(payrecord);
    }

//    @Override
//    public Page<Payrecord> getPayRecord(Page<Payrecord> page, String date) {
//        Page<Payrecord> Page = new Page<Payrecord>();
//        //设置当前页
//        Page.setCurrentPage(page.getCurrentPage());
//        //设置每页条数
//        Page.setPageSize(page.getPageSize());
//        //设置每页数据
//        List<Payrecord> list = dao.getPayRecord(page,date);
//        Page.setLists(list);
//        //设置总条数
//        Page.setTotalRecord(dao.getPayRecordCount(date));
//        return Page;
//    }
//    @Override
//    public Page<Payrecord> getPayRecord1(Page<Payrecord> page, String date) {
//        Page<Payrecord> Page = new Page<Payrecord>();
//        //设置当前页
//        Page.setCurrentPage(page.getCurrentPage());
//        //设置每页条数
//        Page.setPageSize(page.getPageSize());
//        //设置每页数据
//        List<Payrecord> list = dao.getPayRecord1(page,date);
//        Page.setLists(list);
//        //设置总条数
//        Page.setTotalRecord(dao.getPayRecordCount1(date));
//        return Page;
//    }
//
//    @Override
//    public Payrecord getPrice(Payrecord payrecord) {
//        Payrecord pr =new Payrecord();
//        pr.setInPrice(dao.getPayRecordInMoney(payrecord));
//        pr.setOutPrice(dao.getPayRecordOutMoney(payrecord));
//        pr.setInPriceCount(dao.getPayRecordInMoneyCount(payrecord));
//        pr.setOutPriceCount(dao.getPayRecordOutMoneyCount(payrecord));
//        return pr;
//    }


    @Override
    public int getCount(Product product) {
        return dao.getCount(product);
    }

    @Override
    public List<Product> getAllByPage(Page<Product> p, Product product) {
        return dao.getAllByPage(p,product);
    }

    @Override
    public void add(Product product) {

    }

    @Override
    public void del(Product product) {

    }

    @Override
    public void update(Product product) {

    }

    @Override
    public List<Product> getAll() {
        return null;
    }

    @Override
    public List<Product> getAll1() {
        return null;
    }
}
